package com.jdls.tanhua.dubbo.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jdls.tanhua.dubbo.BlackListApi;
import com.jdls.tanhua.dubbo.mapper.BlackListMapper;
import com.jdls.tanhua.dubbo.mapper.QuestionMapper;
import com.jdls.tanhua.pojo.BlackList;
import com.jdls.tanhua.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 嘉德罗斯
 * @date 2021/10/24
 */
@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;


    @Override
    public void delete(Long userId,Long id) {
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getUserId,userId);
        queryWrapper.eq(BlackList::getBlackUserId,id);
        blackListMapper.delete(queryWrapper);
    }

    @Override
    public PageResult findAll(Long id, int page, int pageSize) {

        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getUserId,id);
        List<BlackList> blackLists = blackListMapper.selectList(queryWrapper);
        List<Long> ids = new ArrayList<>();
        for (BlackList blackList : blackLists) {
            ids.add(blackList.getBlackUserId());
        }
        Integer size = blackLists.size();
        PageResult pageResult = new PageResult(page,pageSize,size,ids);
        //Integer pages = size%pageSize == 0? size/pageSize : size / pageSize+1;
        //pageResult.setPages(pages);
        return pageResult;
    }
}
